/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.data;

import java.util.ArrayList;

import android.app.Activity;

import edu.bsu.android.gtv.apps.bconnected.objects.Term;
import edu.bsu.android.gtv.apps.bconnected.parser.ParserFactory;
import edu.bsu.android.gtv.apps.bconnected.parser.ServiceParser;
import edu.bsu.android.gtv.apps.bconnected.util.Constants;

/**
 * Data layer for the {@link Term} object
 * @author Kyle Parker, University Computing Services
 */
public class TermData {
    private static ArrayList<Term> mTerms;

    /**
     * Loads an ArrayList<Term> from the service handler containing the list of current and future terms
     * @param activity - used by the {@link ParserFactory} to retrieve the demo_account shared preference - this will determine what
     * 					 data source to use for the service handler.
     */
    public static void initializeTerm(Activity activity) {
    	ArrayList<String> querystringParms = new ArrayList<String>(2);
		querystringParms.add(Constants.QUERYSTRING_QUERY_ID + Constants.QUERY_TERM_ALL); 
			
		ServiceParser parser = ParserFactory.getParser(Constants.SERVICE_TYPE_TERM, querystringParms, activity);
		mTerms = parser.parseTerm();
    }

    /**
     * Returns the integer value of the {@link Term} object size
     * @return mTerms.size() || 0
     */
    public static int getTermCount() {
    	if (mTerms == null) {
    		return 0;
    	} else {
            return mTerms.size();
    	}
    }

    /**
     * Returns a {@link Term} object at the index specified
     * @param i - the index of the object to be returned
     * @return mTerms.get(i)
     */    
    public static Term getTerm(int i) {
        return mTerms.get(i);
    }

    /**
     * Returns the ArrayList<Term>
     * @return mTerms
     */
    public static ArrayList<Term> getTerms() {
        return mTerms;
    }
}
